//package cn.cdu.basics.config;
//
//import org.springframework.beans.BeansException;
//import org.springframework.beans.factory.config.BeanPostProcessor;
//import org.springframework.stereotype.Component;
//import springfox.documentation.spring.web.plugins.WebMvcRequestHandlerProvider;
//
//import java.lang.reflect.Field;
//import java.util.List;
//import java.util.stream.Collectors;
//
//@Component
//public class SpringFoxHandlerProviderBeanPostProcessor implements BeanPostProcessor {
//    @Override
//    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
//        if (bean instanceof WebMvcRequestHandlerProvider) {
//            customizeSpringfoxHandlerMappings(getHandlerMappings(bean));
//        }
//        return bean;
//    }
//
//    @SuppressWarnings({"rawtypes", "unchecked"})
//    private void customizeSpringfoxHandlerMappings(List mappings) {
//        List copy = (List) mappings.stream()
//                .filter(mapping -> mapping.getClass().getName().contains("RequestMappingInfoHandlerMapping"))
//                .collect(Collectors.toList());
//        mappings.clear();
//        mappings.addAll(copy);
//    }
//
//    @SuppressWarnings("unchecked")
//    private List getHandlerMappings(Object bean) {
//        try {
//            Field field = bean.getClass().getDeclaredField("handlerMappings");
//            field.setAccessible(true);
//            return (List) field.get(bean);
//        } catch (Exception e) {
//            throw new IllegalStateException(e);
//        }
//    }
//}